package com.jiutong.meipenggang.views.popwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.jiutong.meipenggang.R;

/**
 * 作用:
 * Created by 78 on 2017/9/28.
 */

public class TradeChoicePop extends PopupWindow implements View.OnClickListener {

    public void setAll(onAllClickListener all) {
        this.all = all;
    }

    public void setIn(onInClickListener in) {
        this.in = in;
    }

    public void setOut(onOutClickListener out) {
        this.out = out;
    }

    private onAllClickListener all;
    private onInClickListener in;
    private onOutClickListener out;
    private TextView tvAll,tvIn,tvOut;
    private Context mContext;
    private LayoutInflater layoutInflater;

    //设置透明图0-255 默认100
    private int mPopAlpha = 100;

    //默认点击pop外面dismiss
    private boolean mIsTouchBoundDismiss = true;

    public  TradeChoicePop (Context mContext){
        this.mContext = mContext;
        this.layoutInflater = LayoutInflater.from(mContext);
    }

    public void initView() {
        View v = layoutInflater.inflate(R.layout.pop_trade_choice,null);
        tvAll = (TextView) v.findViewById(R.id.tv_pop_trade_record_all);
        tvIn = (TextView) v.findViewById(R.id.tv_pop_trade_record_in);
        tvOut = (TextView) v.findViewById(R.id.tv_pop_trade_record_out);
        initEvent();
    }

    public void initEvent() {
        tvAll.setOnClickListener(this);
        tvIn.setOnClickListener(this);
        tvOut.setOnClickListener(this);
    }

    public void setmPopAlpha(int alpha) {
        this.mPopAlpha = alpha;
    }


    /**
     * 点击外面部分是否消失
     *
     * @param isTouchBoundDismiss
     */
    public void setTouchBoundDismiss(boolean isTouchBoundDismiss) {
        mIsTouchBoundDismiss = isTouchBoundDismiss;
    }

    private void setStyle(){
        tvAll.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tvAll.setBackgroundResource(0);
        tvIn.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tvIn.setBackgroundResource(0);
        tvOut.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tvOut.setBackgroundResource(0);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_pop_trade_record_all:
                setStyle();
                tvAll.setTextColor(mContext.getResources().getColor(R.color.common_blue));
                tvAll.setBackgroundResource(R.color.pop_trade_record_bg);
                all.onClick();
                break;
            case R.id.tv_pop_trade_record_in:
                setStyle();
                tvIn.setTextColor(mContext.getResources().getColor(R.color.common_blue));
                tvIn.setBackgroundResource(R.color.pop_trade_record_bg);
                in.onClick();
                break;
            case R.id.tv_pop_trade_record_out:
                setStyle();
                tvOut.setTextColor(mContext.getResources().getColor(R.color.common_blue));
                tvOut.setBackgroundResource(R.color.pop_trade_record_bg);
                out.onClick();
                break;
        }
    }

    public interface onAllClickListener{
        void onClick();
    }
    public interface onInClickListener{
        void onClick();
    }
    public interface onOutClickListener{
        void onClick();
    }
}
